<?php echo $this->render('link/header.phtml') ?>
//常用变量初始化
var menuCheckUrl=baseUrl+"/link/serverlink/type/check";
var menuDelUrl=baseUrl+"/link/serverlink/type/del";
var module="linkcheck";
var gridTitle="数据筛选";
var dataId="link_id";
var link = Ext.data.Record.create([
          {name: 'link_id', type: 'int'},
           {name: 'link_site_id', type: 'string'},
		   {name: 'link_linktype_id', type: 'string'},
           {name: 'link_keyword_id',type:'string'},
           {name: 'link_address', type: 'string'},
           {name:'link_pr'},
           {name:'link_home_pr'},
           {name: 'link_client_id', type: 'string'},
           {name:'link_ischeck',type:'string'},
           {name:'link_isgoogle'},
           {name:'link_isexist'},
           {name:'link_ischeck'},
           {name:'link_google_cache'},
           {name:'link_isinfo'},
           {name:'keyword_name'},
           {name:'keyword_link'},
           {name:'keyword_pr'}
      ]);
var pr=Ext.data.Record.create([
		{name:'keyword'},
        {name:'target_pr'},
		{name:'pr_0'},
        {name:'pr_1'},
        {name:'pr_2'},
        {name:'pr_3'},
        {name:'pr_4'},
        {name:'pr_5'},
        {name:'pr_6'},
        {name:'pr_7'},
        {name:'pr_8'},
        {name:'pr_9'},
        {name:'pr_10'},
        {name:'total_all'},
        {name:'total_exist'},
        {name:'total_google'}               
]);
var company_combo_store=new Ext.data.JsonStore({
																	  url:baseUrl+'/link/serverclient/type/getcompany',
																	  totalProperty: 'total',
																	  root:'results',
																	  fields:['client_company']
																	}); 
                                                                    
company_combo_store.load();                                                                    
var company_combo=new Ext.form.ComboBox({
										width:210,
										fieldLabel:'选择客户',
										store:company_combo_store,										
        								displayField:'client_company',
        								valueField :'client_company',
										hiddenName:"client_company",
        								typeAhead:true,
        								triggerAction:'all',                       
                                        //hideTrigger: true, //隐藏下拉箭头   
										loadingText: '正在加载...',
                                        pageSize:8,
                                        minChars:1,
                                        queryDelay:300,   
                                        mode :'remote',  
        								emptyText:'请选择...',                                       
        								selectOnFocus:true,
                                        resizable:true, 
                                        listeners:{
                                        	select:function(){
                                            client_combo_store.baseParams.where="client_company='"+this.value+"'";
                                            client_combo_store.reload();
                                        	//ds.load({params:{start:0,limit:30,where:"link_client_id='"+this.value+"'"}});	
                                        	}
                                        }
										 });                                                                      
client_combo_store.load();
var client_combo=new Ext.form.ComboBox({
										width:210,
										fieldLabel:'选择域名',
										store:client_combo_store,										
        								displayField:'client_host',
        								valueField :'client_id',
										hiddenName:"client_id",
        								typeAhead:true,
        								triggerAction:'all',
                                        queryParam:'client_host',                                                                               
                                        //hideTrigger: true, //隐藏下拉箭头   
										loadingText: '正在加载...',
                                        pageSize:8,
                                        minChars:1,
                                        queryDelay:300,   
                                        mode :'remote',  
        								emptyText:'请选择...',                                       
        								selectOnFocus:true,
                                        resizable:true, 
                                        listeners:{
                                        	select:function(){                                           
                                            keyword_combo_store.baseParams.where="keyword_host='"+this.getRawValue()+"'";
                                            keyword_combo_store.reload();
                                             ds.baseParams.where="link_client_id='"+this.value+"'";
                                            ds.reload();
                                        	//ds.load({params:{start:0,limit:30,where:"link_client_id='"+this.value+"'"}});	
                                        	}
                                        }
										 }); 
keyword_combo_store.on("load",function(ds,record,o){
										if(record[0]){
											keyword_combo.setValue(record[0].data.keyword_name);
                                        	}
										});
                                         
var keyword_combo=new Ext.form.ComboBox({
										width:240,
										fieldLabel:'选择关键字',
										store:keyword_combo_store,										
        								displayField:'keyword_name',
        								valueField :'keyword_id',
										hiddenName:"keyword_id",
        								typeAhead:true,
        								triggerAction:'all',                             
										loadingText: '正在加载...',
                                        pageSize:8,
                                        minChars:1,
                                        queryDelay:300,   
                                        mode :'remote',  
        								emptyText:'请选择...',                                       
        								selectOnFocus:true,
                                        shadow:'drop',
                                        resizable:true, 
                                        listeners:{
                                        	select:function(){
                                            ds.baseParams.where="link_keyword_id='"+this.value+"'";
                                            ds.reload();
                                        	//ds.load({params:{start:0,limit:30,where:"link_client_id='"+this.value+"'"}});	
                                        	}
                                        }
										 });   
                                         
var linktype_combo_store_new=new Ext.data.JsonStore({
																	  url:baseUrl+'/link/serverlinktype',
																	  root:'results',
																	  fields:['linktype_id','linktype_name']
																	  });
var linktype_combo=new Ext.form.ComboBox({
										fieldLabel:'链接类型',
										store:linktype_combo_store_new,										
        								displayField:'linktype_name',
        								valueField :'linktype_id',
										hiddenName:"linktype_id",
        								typeAhead:true,
        								triggerAction:'all',                             
										loadingText: '正在加载...',
                                        pageSize:8,
                                        minChars:1,
                                        queryDelay:300,   
                                        mode :'remote',  
        								emptyText:'请选择...',                                       
        								selectOnFocus:true,
                                        shadow:'drop',
                                        resizable:true, 
                                        listeners:{
                                        select:function(){
                                     		ds_reload();
                                        }
                                        }
										 }); 
                                                                               
var ds=new Ext.data.Store({
							  proxy:new Ext.data.HttpProxy({
									url:baseUrl+'/link/statistic'
									}),
							  reader:new Ext.data.JsonReader({
									root:'results',
									totalProperty:'total',
									id:'link_id',
                                    message:'message',
                                    isexist:'isexist',
                                    noexist:'noexist'
									},link)
	});		

var ds2=new Ext.data.Store({
							  proxy:new Ext.data.HttpProxy({
									url:baseUrl+'/link/statistic/type/pr'
									}),
							  reader:new Ext.data.JsonReader({
									root:'results',
									totalProperty:'total',
                                    id:'pr_0'                                  
									},pr)
	});		
var cm2=new Ext.grid.ColumnModel([				
							{header:'关键字',dataIndex:'keyword'},																	
                            {header:'PR值0',dataIndex:'pr_0',width:40},														
                            {header:'1',dataIndex:'pr_1',width:20},														
                            {header:'2',dataIndex:'pr_2',width:20},														
                            {header:'3',dataIndex:'pr_3',width:20},														
                            {header:'4',dataIndex:'pr_4',width:20},														
                            {header:'5',dataIndex:'pr_5',width:20},														
                            {header:'6',dataIndex:'pr_6',width:20},														
                            {header:'7',dataIndex:'pr_7',width:20},														
                            {header:'8',dataIndex:'pr_8',width:20},														
                            {header:'9',dataIndex:'pr_9',width:20},														
                            {header:'PR值10',dataIndex:'pr_10',width:40},
                            {header:'TargetPage PR',dataIndex:'target_pr'},														
                            {header:'链接数量',dataIndex:'total_all',width:60},
                            {header:'链接存在数量',dataIndex:'total_exist',width:60},                            
                            {header:'链接收录数量',dataIndex:'total_google',width:60}
	]);

cm2.defaultSortable = true; 
//定义列模型
var cm=new Ext.grid.ColumnModel([	
							new Ext.grid.CheckboxSelectionModel(),
                            {header:'链接ID',dataIndex:'link_id',width:50,hidden:true},														
                            {header:'关键字',dataIndex:'keyword_name',width:100},														
                            {header:'Target Link',dataIndex:'keyword_link',width:100},														
                            {header:'TR(PR值)',dataIndex:'keyword_pr',width:150},
							{header:'Inbound Link',dataIndex:'link_address',width:250,renderer:show_link},						
                            {header:'InLink(PR)',dataIndex:'link_pr',width:60},
                            {header:'InLink(域名PR)',dataIndex:'link_home_pr',width:60},
                            {header:'Google收录',dataIndex:'link_isgoogle',width:50,renderer:show_check_status},						
                            {header:'是否存在',dataIndex:'link_isexist',width:50,renderer:show_check_status},											
                            {header:'审核状态',dataIndex:'link_ischeck',width:70,renderer:show_check_status}						
	]);
cm.defaultSortable = true; 
var grid2=new Ext.grid.EditorGridPanel({
									store:ds2,
									cm:cm2,									
									height:200,
									minHeight:100,
									autoWidht:true,								
									loadMask:{msg:'加载服务端数据中',store:ds},	
									autoScroll:true,
									stripeRows:true,									
        							animCollapse: false,
									monitorWindowResize: true,	
									clicksToEdit:true,                                    
									sm:new Ext.grid.CheckboxSelectionModel({singleSelect:false}),									
                                    trackMouseOver:true,
                                    viewConfig:{
                                  		emptyText:'<center><font style="font-weight:bold;font-size:16px">没有数据记录</font></center>',
           								forceFit:true
                                    	}
									});
//定义工具栏								 
var tb=new Ext.Toolbar({
					layout:'column',
                    resizable:true,
                    animate:true,
                    width:1300,
                    frame:true,
                    border:false,                   
					items:[
					new Ext.Panel({
                    columnWidth:.3,
                    height:180,
                    layout:'form',
                    border:false,
                    width:400,
                    labelWidth:60,
                    bodyStyle:'padding:5px;',
                    resizable:true,
                    animate:true,
                    items:[
                    	company_combo,
						client_combo,
                        keyword_combo,
                        {
                        layout:'column',
            			border:false,
                        labelWidth:60,
                        items:[
                        {columnWidth:.5,
                        layout:'form',
                        border:false,
                        labelWidth:60,
                        items:[
                        {xtype:'datefield',
                        fieldLabel:'起始时间',
                        format:'Y-m-d',
                    
                        border:false,
                        id:'start_date',
                        value:'<?=date('Y-m-d',time()-86400*30)?>',
                        maxValue:'<?=date('Y-m-d')?>',
                        listeners:{
                        change:function(){
                        ds_reload();	
                        }
                        }
                        }]} ,
                        {columnWidth:.5,
                        layout:'form',
                        border:false,
                        labelWidth:60,
                        items:[
                        {xtype:'datefield',
                        fieldLabel:'结束时间',
                        format:'Y-m-d',
                        border:false,
                        value:'<?=date('Y-m-d')?>',
                        maxValue:'<?=date('Y-m-d',time()+86400)?>',
                        id:"end_date",
                        listeners:{
                        change:function(){
                      	ds_reload();	
                        }
                        }
                        }
                        ]}
                        ]},
                      linktype_combo                                           	
                    ],
                    bbar:[{text:'删除',iconCls:'icn-delete',handler:menuDel}]
                    }),{
                    columnWidth:.6,
                    xtype:'fieldset',
                   	frame:true,
                    border:false,
                    height:200,
                    width:800,
                    layout:'form',
                    items:[grid2]
                    }
                    ]					
	});			
   
  
function ds_reload(){
 	var count=ds.reader.jsonData.message;
	var start_date=Ext.getCmp('start_date').getValue().format('Y-m-d H:i:s');
    var end_date=Ext.getCmp('end_date').getValue().format('Y-m-d H:i:s');
    var link_type=linktype_combo.getValue(); 	
	if(ds.baseParams.where){
    var pattern=/link_keyword_id='\d+'/;
    var link_keyword_id=ds.baseParams.where.match(pattern);
    if(link_keyword_id!=null){
    	ds.baseParams.where=link_keyword_id+" and link_input_date between '"+start_date+"' and '"+end_date+"' ";
    }
    else{
    	ds.baseParams.where=" link_input_date between '"+start_date+"' and '"+end_date+"' ";
    }
    }else{
    ds.baseParams.where="link_input_date between '"+start_date+"' and '"+end_date+"' ";
    }
    if(link_type!=null){
    ds.baseParams.where+="and link_linktype_id= '"+link_type+"' ";
    }
    ds.reload({callback:function(){
    	var count=ds.reader.jsonData.message;
        var isexist=ds.reader.jsonData.isexist;
        var noexist=ds.reader.jsonData.noexist;
        var linkErrorCount=ds.reader.jsonData.message;
   		//Ext.getCmp('linkcount').setValue(count);
        //Ext.getCmp('linkExistCount').setValue(isexist);
    }});
    ds2.load({params:{start:0,limit:20}});
    //console.dir(ds.reader.jsonData.message);
} 

function menuCheckOk(){
menuCheck(true);
}
function menuCheckError(){
menuCheck(false);
}

function menuCheck(flag){
	var selectRows=grid.getSelectionModel().getSelections();												
												if(selectRows.length==0){
													Ext.MessageBox.alert('提示','请选择一条数据');
													}
												else{		
													var message="";
													for(var i=0;i<selectRows.length;i++){
														if(i!=0){
															message+=",";
															}
														message+=selectRows[i].get(dataId);
														}
													Ext.Ajax.request({
																	 url:menuCheckUrl,
																	 params:{id:message,flag:flag},																																		 																	success:function(response,option){
																var temp=Ext.util.JSON.decode(response.responseText);																
																ds.load({params:{start:0,limit:30}});
																grid.render();
																		 },
																	failure:function(response,option){
																		var temp=Ext.util.JSON.decode(response.responseText);
																		Ext.MessageBox.alert('waring',temp.msg);
																		}
																	 });
													}
}

<?php echo $this->render('link/foot.phtml') ?>
